package com.yhp.dao.impl;

import com.yhp.bean.Grade;
import com.yhp.dao.GradeDao;
import com.yhp.utils.DBUtils;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtils implements GradeDao {
    @Override
    public List<Grade> getGradeList() {
        List<Grade> list = new ArrayList<>();
        try {
            String sql = "select * from grade ";
            PreparedStatement pps = getPps(sql);
            resultSet = pps.executeQuery();
            while (resultSet.next()){
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeid"));
                grade.setGradeName(resultSet.getString("gradename"));
                list.add(grade);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return list;
    }
}
